package com.qclix.inv.pdf;

import com.qclix.inv.Invoice;
import com.qclix.inv.Timesheet;

import org.slf4j.Logger;

/**
 * Implements the Invoice PDF generation
 */
public class InvoicePdfGenerationServiceDefaultImpl implements InvoicePdfGenerationService {

    private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(InvoicePdfGenerationServiceDefaultImpl.class);

    private PDFCreator pdfCreator;


    public void setPdfCreator(PDFCreator pdfCreator) {
        this.pdfCreator = pdfCreator;
    }

    public byte[] getPDF(Invoice invoice) {
    	if (LOGGER.isTraceEnabled()) {
    		LOGGER.debug("creating PDF (bytes) for invoice " + invoice.getNumber());
    	}
        return pdfCreator.getPDF(invoice);

    }
    
    public byte[] getPDF(Timesheet timesheet) {
    	if (LOGGER.isTraceEnabled()) {
    		LOGGER.debug("creating PDF (bytes) for timesheet (" + timesheet.getClientName() + " / " + timesheet.getProjectName() + " / "+ timesheet.getConsultant() + ")");
    	}
        try {
            return pdfCreator.getPDF(timesheet);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
